home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / fmtline.exe / FMTDEMO.PAS < prev    next >
Pascal/Delphi Source File  |  1993-02-14  |  8KB  |  236 lines

  1. {************************************************}
  2. {                                                }
  3. {   Turbo Pascal 6.0                             }
  4. {   Demo program FmtDemo.pas for unit FmtLine,   }
  5. {   TVGUID16.pas Demo program from the TV Guide  }
  6. {                                                }
  7. {************************************************}
  8.  
  9. {$X+}
  10.  
  11. program ValidateFormatDemo;
  12.  
  13. uses Objects, Drivers, Views,      {std. TV units}
  14. Menus, Dialogs, App, Msgbox,       { ditto       }
  15. FmtLine;                  {modified Formline unit}
  16.  
  17. const
  18.   cmNewDialog = 101;
  19.  
  20. var
  21.   Value: real;
  22. type                          {declare the type of data record to use in box}
  23.   DataRec                   = RECORD
  24.    Field1                    : string [ 30 ] ; {NameFormatline}
  25.    Field2                    : real          ; {MoneyFormatline}
  26.    Field3                    : string [ 14 ] ; {PhoneFormatline}
  27.    Field4                    : string [ 10 ] ; {ZipFormatline}
  28.    Field5                    : real          ; {RealFormatline}
  29.    Field6                    : integer       ; {IntegerFormatline}
  30.    Field7                    : real          ; {LatlongFormatline}
  31.    Field8                    : real          ; {TimeFormatline}
  32.   END ;
  33.  
  34.  
  35.   TMyApp = object(TApplication)
  36.     procedure HandleEvent(var Event: TEvent); virtual;
  37.     procedure InitMenuBar; virtual;
  38.     procedure InitStatusLine; virtual;
  39.     procedure NewDialog;
  40.   end;
  41.  
  42.   PDemoDialog = ^TDemoDialog;
  43.   TDemoDialog = object(TDialog)
  44.   end;
  45.  
  46. var
  47.   DemoDialogData: DataRec;  {declare name of data record variable in box }
  48.                             {you need a name since you could have two    }
  49.                             {instances of the box, each with its own data}
  50.  
  51. { TMyApp }
  52. procedure TMyApp.HandleEvent(var Event: TEvent);
  53. begin
  54.   TApplication.HandleEvent(Event);
  55.   if Event.What = evCommand then
  56.   begin
  57.     case Event.Command of
  58.       cmNewDialog: NewDialog;
  59.     else
  60.       Exit;
  61.     end;
  62.     ClearEvent(Event);
  63.   end;
  64. end;
  65.  
  66. procedure TMyApp.InitMenuBar;
  67. var R: TRect;
  68. begin
  69.   GetExtent(R);
  70.   R.B.Y := R.A.Y + 1;
  71.   MenuBar := New(PMenuBar, Init(R, NewMenu(
  72.     NewSubMenu('~F~ile', hcNoContext, NewMenu(
  73.       NewItem('E~x~it', 'Alt-X', kbAltX, cmQuit, hcNoContext,
  74.       nil)),
  75.     NewSubMenu('~D~ialog', hcNoContext, NewMenu(
  76.       NewItem('~V~alidate', 'F2', kbF2, cmNewDialog, hcNoContext,
  77.       nil)),
  78.     nil))
  79.   )));
  80. end;
  81.  
  82. procedure TMyApp.InitStatusLine;
  83. var R: TRect;
  84. begin
  85.   GetExtent(R);
  86.   R.A.Y := R.B.Y - 1;
  87.   StatusLine := New(PStatusLine, Init(R,
  88.     NewStatusDef(0, $FFFF,
  89.       NewStatusKey('~F10~ Menu', kbF10, cmMenu,
  90.       NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit,
  91.       NewStatusKey('~F2~ Dialog', kbF2, cmNewDialog,
  92.       NewStatusKey('            <<Input Validator>>   SA Midwinter',
  93.                                 kbNoKey, cmError,
  94.       nil)))),
  95.     nil)
  96.   ));
  97. end;
  98.  
  99.    {Dialog box built with Shazam 2, Turbo Vision  }
  100.    {code generator by Jonathan J. Stein, 76576,470} 
  101.  
  102. procedure TMyApp.NewDialog;
  103.  
  104. var
  105.    Dlg                       : PDemoDialog ;
  106.    R                         : TRect ; 
  107.    Control                   : PInputline;
  108.    Labl, Histry,
  109.    Button, Bruce             : PView ;
  110.    C                         : word;
  111.  
  112. begin
  113.    R.Assign ( 3 , 1 , 54 , 20 ) ; 
  114.   Dlg := New(PDemoDialog, Init(R, 'tFormatLine Descendants'));
  115.   with Dlg^ do
  116.   begin
  117.    R.Assign ( 12 , 2 , 37 , 3 ) ; 
  118.    Control                   := New ( PNameFormatLine , Init ( R , 30 ) ) ;
  119.    Control^.HelpCtx          := hcNoContext ;
  120.    Dlg^.Insert ( Control ) ; 
  121.    {the Dlg^ is redundant since we have a 'With Dlg^ do' }
  122.    R.Assign ( 7 , 2 , 12 , 3 ) ;
  123.    Labl                      := New ( PLabel , Init ( R , '~N~ame' , Control ) ) ;
  124.    Dlg^.Insert ( Labl ) ;
  125.  
  126.    R.Assign ( 12 , 4 , 32 , 5 ) ; 
  127.    Control                   := New ( PMoneyFormatLine , Init ( R , 30 ) ) ;
  128.    Dlg^.Insert ( Control ) ; 
  129.    R.Assign ( 6 , 4 , 12 , 5 ) ;
  130.    Labl                      := New ( PLabel , Init ( R , '~M~oney' , Control ) ) ;
  131.    Dlg^.Insert ( Labl ) ;
  132.  
  133.    R.Assign ( 12 , 6 , 29 , 7 ) ;
  134.    Control                   := New ( PPhoneFormatLine , Init ( R , 14 ) ) ;
  135.    Dlg^.Insert ( Control ) ; 
  136.    R.Assign ( 6 , 6 , 12 , 7 ) ;
  137.    Labl                      := New ( PLabel , Init ( R , '~P~hone' , Control ) ) ;
  138.    Dlg^.Insert ( Labl ) ;
  139.  
  140.    R.Assign ( 12 , 8 , 22 , 9 ) ; 
  141.    Control                   := New ( PZipFormatLine , Init ( R , 10 ) ) ;
  142.    Dlg^.Insert ( Control ) ; 
  143.    R.Assign ( 1 , 8 , 12 , 9 ) ; 
  144.    Labl                      := New ( PLabel , Init ( R , '~Z~ip/Postal' , Control ) ) ;
  145.    Dlg^.Insert ( Labl ) ;
  146.  
  147.    R.Assign ( 12 , 10 , 27 , 11 ) ; 
  148.    Control                   := New ( PRealFormatLine , Init ( R , 15 ) ) ;
  149.    Dlg^.Insert ( Control ) ; 
  150.    R.Assign ( 7 , 10 , 12 , 11 ) ;
  151.    Labl                      := New ( PLabel , Init ( R , '~R~eal' , Control ) ) ;
  152.    Dlg^.Insert ( Labl ) ;
  153.  
  154.    R.Assign ( 12 , 12 , 19 , 13 ) ;
  155.    Control                   := New ( PIntegerFormatLine , Init ( R , 15 ) ) ;
  156.    Control^.HelpCtx          := hcNOCONTEXT ; 
  157.    Dlg^.Insert ( Control ) ; 
  158.    R.Assign ( 4 , 12 , 12 , 13 ) ; 
  159.    Labl                      := New ( PLabel , Init ( R , '~I~nteger' , Control ) ) ;
  160.    Dlg^.Insert ( Labl ) ;
  161.  
  162.    R.Assign ( 12 , 14 , 27 , 15 ) ;
  163.    Control                   := New ( PLongFormatLine , Init ( R , 15 ) ) ;
  164.    Dlg^.Insert ( Control ) ; 
  165.    R.Assign ( 2 , 14 , 12 , 15 ) ;
  166.    Labl                      := New ( PLabel , Init ( R , '~L~ongitude' , Control ) ) ;
  167.    Dlg^.Insert ( Labl ) ;
  168.  
  169.    R.Assign ( 12 , 16 , 25 , 17 ) ; 
  170.    Control                   := New ( PTimeFormatLine , Init ( R , 15 ) ) ;
  171.    Dlg^.Insert ( Control ) ; 
  172.    R.Assign ( 7 , 16 , 12 , 17 ) ; 
  173.    Labl                      := New ( PLabel , Init ( R , '~T~ime' , Control ) ) ;
  174.    Dlg^.Insert ( Labl ) ;
  175.  
  176.    R.Assign ( 38 , 11 , 46 , 13 ) ; 
  177.    Button                    := New ( PButton , Init ( R , '~O~k' , cmOK , bfDefault ) ) ;
  178.    Dlg^.Insert ( Button  ) ; 
  179.    R.Assign ( 37 , 14 , 47 , 16 ) ;
  180.    Button                    := New ( PButton , Init ( R , 'Cancel' , cmCancel , bfNormal ) ) ;
  181.    Dlg^.Insert ( Button  ) ; 
  182.  
  183.    R.Assign ( 9 , 18 , 17 , 19 ) ; 
  184.    Bruce                     := New ( PStaticText , Init ( R , 'TAB-next' ) ) ;
  185.    Dlg^.Insert ( Bruce   ) ;
  186.    R.Assign ( 24 , 18 , 37 , 19 ) ; 
  187.    Bruce                     := New ( PStaticText , Init ( R , 'ShiftTAB-prev' ) ) ;
  188.    Dlg^.Insert ( Bruce   ) ; 
  189.  
  190. end; {end of With Dlg^ do}
  191.  
  192.   Dlg^.SetData(DemoDialogData);
  193.   C := DeskTop^.ExecView(Dlg);
  194.   if C <> cmCancel then Dlg^.GetData(DemoDialogData);
  195.  
  196.   {in a real app, you would insert here methods for using the data}
  197.   {you have collected, for example the following nonsense:        }
  198.  
  199.     With DemoDialogData do
  200.     begin
  201.       Value:= Field2 {money} * Field8 {time} / Field7 {longitude};
  202.       if Value > 100 then
  203.          Messagebox(#3'I''m rich, I''m rich!!',
  204.                     nil, mfInformation+mfOkButton)
  205.       else
  206.          Messagebox(#3'Oh well, back to work...',
  207.                     nil, mfInformation+mfOkButton);
  208.     end;
  209.  
  210.   Dispose(Dlg, Done);
  211. end;
  212.  
  213. var
  214.   MyApp: TMyApp;
  215.  
  216. begin  {initialise data record}
  217.   with DemoDialogData do
  218.   begin
  219.    Field1 := 'Brian Mulroney' {string [ 30 ] } ; {NameFormatline}
  220.    Field2 := 276543.21        {real          } ; {MoneyFormatline}
  221.    Field3 := '(403) 230-7769' {string [ 14 ] } ; {PhoneFormatline}
  222.    Field4 := 'T2M 1S4'        {string [ 10 ] } ; {ZipFormatline}
  223.    Field5 := 123.456789       {real          } ; {RealFormatline}
  224.    Field6 := 16384            {integer       } ; {IntegerFormatline}
  225.    Field7 := -121.3456        {real          } ; {LatlongFormatline}
  226.    Field8 := 17.3377          {real          } ; {TimeFormatline}
  227.   end;
  228.   MyApp.Init;
  229.   MessageBox(#3'Validated Input Line Tester'#13
  230.              +#3'released into the public domain by'#13
  231.              +#3'Stewart Midwinter 74670,1306',
  232.              nil,mfInformation+mfOkButton);
  233.   MyApp.Run;
  234.   MyApp.